package com.zjc.activiti;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.junit.Test;

import java.util.List;

public class Approve extends BaseActiviti {

    @Test
    public  void deploy(){
        super.baseDeploy("approve_process.bpmn");
    }

    @Test
    public void startProcess(){
        RuntimeService runtimeService=processEngine.getRuntimeService();
        ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("approve_process");
        System.out.println("流程实例"+processInstance.getId());
        System.out.println("流程定义id:"+processInstance.getProcessDefinitionId());
    }

    @Test
    public  void queryMyTask(){
        TaskService taskService =processEngine.getTaskService();
        TaskQuery taskQuery=taskService.createTaskQuery();//创建查询查询任务
        taskQuery.taskVariableValueEquals("zjc_ttt","zjc_ttt1");
        List<Task> taskList=taskQuery.list();
        if (taskList != null && taskList.size() > 0) {
            for (Task task:taskList) {
                System.out.println("任务定义的key:"+task.getTaskDefinitionKey());//对应节点的id
                System.out.println("任务ID:"+task.getId());
                System.out.println("任务名称:"+task.getName());
                System.out.println("任务的创建时间"+task.getCreateTime());
                System.out.println("任务的办理人:"+task.getAssignee());
                System.out.println("流程实例ID:"+task.getProcessInstanceId());
                System.out.println("执行对象ID:"+task.getExecutionId());
                System.out.println("流程定义ID:"+task.getProcessDefinitionId());
//                if(task.getProcessDefinitionId().equals("approve_process:1:270010")){
//                    continue;
//                }
                //processEngine.getTaskService().complete(task.getId());
                System.out.println("#################################");
            }
        }
    }

    public  void completeMyTask(){

    }
}
